import Api from 'wx-axios-promise'
let api = Api()


//拦截request
api.interceptors.request.use(function (config){
    console.log(config)
    let token = wx.getStorageSync('token');
    if(!config.header) {
      config.header = {}
    }
    config.header.Authorization = token;
    return config;
}, function(error){
  console.log('request error:', error);
    return error
})
 

//拦截response
api.interceptors.response.use(function (config){
  //接口||wx.接口
  if(config.header && config.header.hasOwnProperty('Authorization')) {
    wx.setStorageSync('token', config.header.Authorization);
  }
  console.log('response', config);
  return config.data || config
}, function(error){
    return error
})

export {api};